﻿import traceback
from datetime import date
from string import Template

from DataAccess.DBConnFactory import DBConnFactory


def recover_updates_driven_by_dividend(ref_date):
	conn = DBConnFactory().get_db_connection('PKEDB')
	cursor = conn.cursor()
	cursor.execute("delete from cash_dividend_flow where event_date=TO_DATE(:1,'yyy-mm-dd')", ref_date.isoformat())
	cursor.execute("delete from stock_dividend_flow where event_date=TO_DATE(:1,'yyy-mm-dd')", ref_date.isoformat())
	cursor.execute("delete from position where ref_date>=TO_DATE(:1,'yyy-mm-dd')", ref_date.isoformat())	
	conn.commit()
	print 'info, delete complete.'
	

def clear_all():
	conn = DBConnFactory().get_db_connection('PKEDB')
	cursor = conn.cursor()
	cursor.execute("truncate table cash_dividend_flow")
	cursor.execute("truncate table stock_dividend_flow")
	cursor.execute("truncate table pnote_info")
	cursor.execute("truncate table position")
	cursor.execute("truncate table repo_info")
	cursor.execute("truncate table transaction")
	conn.commit()
	print 'info, clear tables complete.'